package ru.papergames.battleserver.network.serverpackets.flashuser;

import ru.papergames.battleserver.model.battle.AbstractBattle;
import ru.papergames.battleserver.model.battle.BallColor;
import ru.papergames.battleserver.model.battle.GameBallsLine;
import ru.papergames.battleserver.model.battle.map.Cell;
import ru.papergames.battleserver.model.battle.map.LinesToBeRemovedInfo;

import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * @author : atroshanin
 */
public class BattleRemoveBallsInLines extends PaperGameServerPacket {

    private AbstractBattle battle;
    private Set<Cell> cellsToBeFree;
    private List<GameBallsLine> lines;
    private BallColor ballsColor;

    public BattleRemoveBallsInLines(AbstractBattle battle, LinesToBeRemovedInfo linesToBeRemovedInfo, BallColor ballsColor) {
        this.battle = battle;
        this.cellsToBeFree = linesToBeRemovedInfo.getCellsInLines();
        this.lines = linesToBeRemovedInfo.getLines();
        this.ballsColor = ballsColor;
    }

    public Set<Cell> getCellsToBeFree() {
        return Collections.unmodifiableSet(cellsToBeFree);
    }

    public List<GameBallsLine> getLines() {
        return lines;
    }

    public BallColor getBallsColor() {
        return ballsColor;
    }

    @Override
    protected int getPacketId() {
        return BATTLE_REMOVE_BALLS_IN_LINES_PACKET_ID;
    }

    @Override
    protected void writePacketData() {
        writeD(battle.getBattleOrderId());
        writeH(cellsToBeFree.size());
        for (Cell cell : cellsToBeFree) {
            writeH(cell.getX());
            writeH(cell.getY());
        }
    }

}
